<?php

namespace app\index\model;
use \think\Model;
class Cate extends Model
{
//    获取所有的子栏目id
    public function getchilredid($cateid){
        $cateres = $this->select();
        $arr = $this->_getchilrenid($cateres,$cateid);
        $arr[] = $cateid;
        $cateId = implode(',',$arr);
        return $cateId;
    }
    public function _getchilrenid($cateres,$cateid){
        static $arr = array();
        foreach ($cateres as $k=>$v){
            if ($v['pid'] ==$cateid){
                $arr[] = $v['id'];
                $this->_getchilrenid($cateres,$v['id']);
            }
        }
        return $arr;
    }



//    分类对文章是一对多
    public function articles()
    {
        return $this->hasMany('Article','cate_id');
    }


}
